'use strict';

global.noteList = [];
global.noteVersion = 10;

const getNoteVersion = () => {
  if (!global.noteVersion) {
    global.noteVersion = 10;
  }

  return global.noteVersion;
};

const setNoteVersion = version => {
  const versionNumber = JSON.parse(version);
  global.noteVersion = versionNumber;
};

const getNotes = () => {
  return global.noteList;
};

const saveNote = (note, index) => {
  if (!global.noteList) {
    global.noteList = [];
  }

  global.noteList[index] = note;
};

const addNote = notes => {
  global.noteList.push(notes);
};

const saveNotes = notes => {
  global.noteList = notes;
};

const delNote = index => {
  global.noteList.splice(index, 1);
};

module.exports = {
  getNoteVersion,
  setNoteVersion,
  getNotes,
  saveNote,
  saveNotes,
  addNote,
  delNote,
};
